home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10368 < prev    next >
Encoding:
Text File  |  1996-08-05  |  17.6 KB  |  728 lines

  1. Path: news.applink.net!haskett
  2. From: haskett@news.applink.net (Brian Haskett)
  3. Newsgroups: comp.lang.c++
  4. Subject: reference counting (and inheritance)
  5. Date: 7 Mar 1996 15:20:25 GMT
  6. Organization: AppLink Corp.
  7. Sender: haskett@applink.net
  8. Message-ID: <4hmurp$rs4@news2.nkn.net>
  9. NNTP-Posting-Host: applink.applink.net
  10.  
  11. I am attempting to implement reference counting classes that allow me
  12. to have "smart" pointers to database objects.  The reference classes
  13. keep a counter in the db object of how many references are currently 
  14. pointing to that object, and when the count reaches zero, the object is 
  15. deleted from the heap with the "delete" operator.
  16.  
  17. The problem is that the reference class template that I created does not
  18. follow the same conversion rules as standard pointer conversions.
  19. ARM r.4.6 describes that "A pointer to a class may be converted to
  20. a pointer to an accessible base class of that class."  I need that
  21. kind of behavior with my reference class.
  22.  
  23. I have the following example that demonstrates the problem:
  24.  
  25. template <class T>
  26. class JtsRefT
  27. {
  28. private:
  29.         T       *ptr;
  30.  
  31. public:
  32.         JtsRefT (T *t=NULL) : ptr(t) { if (t!=NULL) t->IncRefCount(); }
  33.         ~JtsRefT () { if (ptr!=NULL && ptr->DecRefCount()==0) delete ptr; }
  34.  
  35.         operator T* () const { return ptr; }
  36.  
  37.         const T* operator-> () const { return ptr; }
  38.         T* operator-> () { return ptr; }
  39.  
  40.         const T& operator* () const { return *ptr; }
  41.         T& operator* () { return *ptr; }
  42. };
  43.  
  44. class A
  45. {
  46. private:
  47.         long    refCount;
  48.  
  49. public:
  50.         long IncRefCount () { return ++refCount; }
  51.         long DecRefCount () { return --refCount; }
  52. };
  53.  
  54. typedef JtsRefT<A> AREF;
  55.  
  56. class B : public A
  57. {
  58. };
  59.  
  60. typedef JtsRefT<B> BREF;
  61.  
  62. main ()
  63. {
  64.         BREF bref;
  65.         AREF aref=bref;
  66.  
  67.         return 0;
  68. };
  69.  
  70.  
  71. When compiling on AIX 3.2.5, I correctly get the following error:
  72. "test66.C", line 43.19: 1540-228: (S) No suitable constructor or conversion 
  73. function exists for conversion from "BREF" to "JtsRefT<A>".
  74. make: 1254-004 The error code from the last command is 1.
  75.  
  76. How can I modify my implementation to follow the standard pointer 
  77. conversion ?
  78.  
  79. -thanks
  80. Brian Haskett
  81. haskett@vnet.ibm.com
  82. haskett@applink.net
  83. Newsgroups: comp.lang.c++
  84. Subject: Reference Counting (and Inheritance)
  85. Summary: 
  86. Expires: 
  87. Sender: haskett@applink.net
  88. Followup-To: 
  89. Distribution: 
  90. Organization: AppLink Corp.
  91. Keywords: 
  92.  
  93. Newsgroups: comp.lang.c++
  94. Subject: Reference Counting Pointers to Objects
  95. Summary: 
  96. Expires: 
  97. Sender: haskett@applink.net
  98. Followup-To: 
  99. Distribution: 
  100. Organization: AppLink Corp.
  101. Keywords: 
  102.  
  103. I am attempting to implement reference counting classes that allow me
  104. to have "smart" pointers to database objects.  The reference classes
  105. keep a counter in the db object of how many references are currently 
  106. pointing to that object, and when the count reaches zero, the object is 
  107. deleted from the heap with the "delete" operator.
  108.  
  109. The problem is that the reference class template that I created does not
  110. follow the same conversion rules as standard pointer conversions.
  111. ARM r.4.6 describes that "A pointer to a class may be converted to
  112. a pointer to an accessible base class of that class."  I need that
  113. kind of behavior with my reference class.
  114.  
  115. I have the following example that demonstrates the problem:
  116.  
  117. template <class T>
  118. class JtsRefT
  119. {
  120. private:
  121.         T       *ptr;
  122.  
  123. public:
  124.         JtsRefT (T *t=NULL) : ptr(t) { if (t!=NULL) t->IncRefCount(); }
  125.         ~JtsRefT () { if (ptr!=NULL && ptr->DecRefCount()==0) delete ptr; }
  126.  
  127.         operator T* () const { return ptr; }
  128.  
  129.         const T* operator-> () const { return ptr; }
  130.         T* operator-> () { return ptr; }
  131.  
  132.         const T& operator* () const { return *ptr; }
  133.         T& operator* () { return *ptr; }
  134. };
  135.  
  136. class A
  137. {
  138. private:
  139.         long    refCount;
  140.  
  141. public:
  142.         long IncRefCount () { return ++refCount; }
  143.         long DecRefCount () { return --refCount; }
  144. };
  145.  
  146. typedef JtsRefT<A> AREF;
  147.  
  148. class B : public A
  149. {
  150. };
  151.  
  152. typedef JtsRefT<B> BREF;
  153.  
  154. main ()
  155. {
  156.         BREF bref;
  157.         AREF aref=bref;
  158.  
  159.         return 0;
  160. };
  161.  
  162.  
  163. When compiling on AIX 3.2.5, I correctly get the following error:
  164. "test66.C", line 43.19: 1540-228: (S) No suitable constructor or conversion 
  165. function exists for conversion from "BREF" to "JtsRefT<A>".
  166. make: 1254-004 The error code from the last command is 1.
  167.  
  168. How can I modify my implementation to follow the standard pointer 
  169. conversion ?
  170.  
  171. -thanks
  172. Brian Haskett
  173. haskett@vnet.ibm.com
  174. haskett@applink.net
  175. Newsgroups: comp.lang.c++
  176. Subject: Reference Counting (inheritance)
  177. Summary: 
  178. Expires: 
  179. Sender: 
  180. Followup-To: 
  181. Distribution: 
  182. Organization: AppLink Corp.
  183. Keywords: 
  184.  
  185. Newsgroups: comp.lang.c++
  186. Subject: Reference Counting Pointers to Objects
  187. Summary: 
  188. Expires: 
  189. Sender: haskett@applink.net
  190. Followup-To: 
  191. Distribution: 
  192. Organization: AppLink Corp.
  193. Keywords: 
  194.  
  195. I am attempting to implement reference counting classes that allow me
  196. to have "smart" pointers to database objects.  The reference classes
  197. keep a counter in the db object of how many references are currently 
  198. pointing to that object, and when the count reaches zero, the object is 
  199. deleted from the heap with the "delete" operator.
  200.  
  201. The problem is that the reference class template that I created does not
  202. follow the same conversion rules as standard pointer conversions.
  203. ARM r.4.6 describes that "A pointer to a class may be converted to
  204. a pointer to an accessible base class of that class."  I need that
  205. kind of behavior with my reference class.
  206.  
  207. I have the following example that demonstrates the problem:
  208.  
  209. template <class T>
  210. class JtsRefT
  211. {
  212. private:
  213.         T       *ptr;
  214.  
  215. public:
  216.         JtsRefT (T *t=NULL) : ptr(t) { if (t!=NULL) t->IncRefCount(); }
  217.         ~JtsRefT () { if (ptr!=NULL && ptr->DecRefCount()==0) delete ptr; }
  218.  
  219.         operator T* () const { return ptr; }
  220.  
  221.         const T* operator-> () const { return ptr; }
  222.         T* operator-> () { return ptr; }
  223.  
  224.         const T& operator* () const { return *ptr; }
  225.         T& operator* () { return *ptr; }
  226. };
  227.  
  228. class A
  229. {
  230. private:
  231.         long    refCount;
  232.  
  233. public:
  234.         long IncRefCount () { return ++refCount; }
  235.         long DecRefCount () { return --refCount; }
  236. };
  237.  
  238. typedef JtsRefT<A> AREF;
  239.  
  240. class B : public A
  241. {
  242. };
  243.  
  244. typedef JtsRefT<B> BREF;
  245.  
  246. main ()
  247. {
  248.         BREF bref;
  249.         AREF aref=bref;
  250.  
  251.         return 0;
  252. };
  253.  
  254.  
  255. When compiling on AIX 3.2.5, I correctly get the following error:
  256. "test66.C", line 43.19: 1540-228: (S) No suitable constructor or conversion 
  257. function exists for conversion from "BREF" to "JtsRefT<A>".
  258. make: 1254-004 The error code from the last command is 1.
  259.  
  260. How can I modify my implementation to follow the standard pointer 
  261. conversion ?
  262.  
  263. -thanks
  264. Brian Haskett
  265. haskett@vnet.ibm.com
  266. haskett@applink.net
  267. Newsgroups: comp.lang.c++
  268. Subject: Reference Counting (and Inheritance)
  269. Summary: 
  270. Expires: 
  271. Sender: haskett@applink.net
  272. Followup-To: 
  273. Distribution: 
  274. Organization: AppLink Corp.
  275. Keywords: 
  276.  
  277. Newsgroups: comp.lang.c++
  278. Subject: Reference Counting Pointers to Objects
  279. Summary: 
  280. Expires: 
  281. Sender: haskett@applink.net
  282. Followup-To: 
  283. Distribution: 
  284. Organization: AppLink Corp.
  285. Keywords: 
  286.  
  287. I am attempting to implement reference counting classes that allow me
  288. to have "smart" pointers to database objects.  The reference classes
  289. keep a counter in the db object of how many references are currently 
  290. pointing to that object, and when the count reaches zero, the object is 
  291. deleted from the heap with the "delete" operator.
  292.  
  293. The problem is that the reference class template that I created does not
  294. follow the same conversion rules as standard pointer conversions.
  295. ARM r.4.6 describes that "A pointer to a class may be converted to
  296. a pointer to an accessible base class of that class."  I need that
  297. kind of behavior with my reference class.
  298.  
  299. I have the following example that demonstrates the problem:
  300.  
  301. template <class T>
  302. class JtsRefT
  303. {
  304. private:
  305.         T       *ptr;
  306.  
  307. public:
  308.         JtsRefT (T *t=NULL) : ptr(t) { if (t!=NULL) t->IncRefCount(); }
  309.         ~JtsRefT () { if (ptr!=NULL && ptr->DecRefCount()==0) delete ptr; }
  310.  
  311.         operator T* () const { return ptr; }
  312.  
  313.         const T* operator-> () const { return ptr; }
  314.         T* operator-> () { return ptr; }
  315.  
  316.         const T& operator* () const { return *ptr; }
  317.         T& operator* () { return *ptr; }
  318. };
  319.  
  320. class A
  321. {
  322. private:
  323.         long    refCount;
  324.  
  325. public:
  326.         long IncRefCount () { return ++refCount; }
  327.         long DecRefCount () { return --refCount; }
  328. };
  329.  
  330. typedef JtsRefT<A> AREF;
  331.  
  332. class B : public A
  333. {
  334. };
  335.  
  336. typedef JtsRefT<B> BREF;
  337.  
  338. main ()
  339. {
  340.         BREF bref;
  341.         AREF aref=bref;
  342.  
  343.         return 0;
  344. };
  345.  
  346.  
  347. When compiling on AIX 3.2.5, I correctly get the following error:
  348. "test66.C", line 43.19: 1540-228: (S) No suitable constructor or conversion 
  349. function exists for conversion from "BREF" to "JtsRefT<A>".
  350. make: 1254-004 The error code from the last command is 1.
  351.  
  352. How can I modify my implementation to follow the standard pointer 
  353. conversion ?
  354.  
  355. -thanks
  356. Brian Haskett
  357. haskett@vnet.ibm.com
  358. haskett@applink.net
  359. Newsgroups: comp.lang.c++
  360. Subject: 
  361. Summary: 
  362. Expires: 
  363. Sender: 
  364. Followup-To: 
  365. Distribution: 
  366. Organization: AppLink Corp.
  367. Keywords: 
  368.  
  369.  
  370. Newsgroups: comp.lang.c++
  371. Subject: reference counting (inheritance)
  372. Summary: 
  373. Expires: 
  374. Sender: 
  375. Followup-To: 
  376. Distribution: 
  377. Organization: AppLink Corp.
  378. Keywords: 
  379.  
  380. I am attempting to implement reference counting classes that allow me
  381. to have "smart" pointers to database objects.  The reference classes
  382. keep a counter in the db object of how many references are currently 
  383. pointing to that object, and when the count reaches zero, the object is 
  384. deleted from the heap with the "delete" operator.
  385.  
  386. The problem is that the reference class template that I created does not
  387. follow the same conversion rules as standard pointer conversions.
  388. ARM r.4.6 describes that "A pointer to a class may be converted to
  389. a pointer to an accessible base class of that class."  I need that
  390. kind of behavior with my reference class.
  391.  
  392. I have the following example that demonstrates the problem:
  393.  
  394. template <class T>
  395. class JtsRefT
  396. {
  397. private:
  398.         T       *ptr;
  399.  
  400. public:
  401.         JtsRefT (T *t=NULL) : ptr(t) { if (t!=NULL) t->IncRefCount(); }
  402.         ~JtsRefT () { if (ptr!=NULL && ptr->DecRefCount()==0) delete ptr; }
  403.  
  404.         operator T* () const { return ptr; }
  405.  
  406.         const T* operator-> () const { return ptr; }
  407.         T* operator-> () { return ptr; }
  408.  
  409.         const T& operator* () const { return *ptr; }
  410.         T& operator* () { return *ptr; }
  411. };
  412.  
  413. class A
  414. {
  415. private:
  416.         long    refCount;
  417.  
  418. public:
  419.         long IncRefCount () { return ++refCount; }
  420.         long DecRefCount () { return --refCount; }
  421. };
  422.  
  423. typedef JtsRefT<A> AREF;
  424.  
  425. class B : public A
  426. {
  427. };
  428.  
  429. typedef JtsRefT<B> BREF;
  430.  
  431. main ()
  432. {
  433.         BREF bref;
  434.         AREF aref=bref;
  435.  
  436.         return 0;
  437. };
  438.  
  439.  
  440. When compiling on AIX 3.2.5, I correctly get the following error:
  441. "test66.C", line 43.19: 1540-228: (S) No suitable constructor or conversion 
  442. function exists for conversion from "BREF" to "JtsRefT<A>".
  443. make: 1254-004 The error code from the last command is 1.
  444.  
  445. How can I modify my implementation to follow the standard pointer 
  446. conversion ?
  447.  
  448. -thanks
  449. Brian Haskett
  450. haskett@vnet.ibm.com
  451. haskett@applink.net
  452. Newsgroups: comp.lang.c++
  453. Subject: Reference Counting (and Inheritance)
  454. Summary: 
  455. Expires: 
  456. Sender: haskett@applink.net
  457. Followup-To: 
  458. Distribution: 
  459. Organization: AppLink Corp.
  460. Keywords: 
  461.  
  462. Newsgroups: comp.lang.c++
  463. Subject: Reference Counting Pointers to Objects
  464. Summary: 
  465. Expires: 
  466. Sender: haskett@applink.net
  467. Followup-To: 
  468. Distribution: 
  469. Organization: AppLink Corp.
  470. Keywords: 
  471.  
  472. I am attempting to implement reference counting classes that allow me
  473. to have "smart" pointers to database objects.  The reference classes
  474. keep a counter in the db object of how many references are currently 
  475. pointing to that object, and when the count reaches zero, the object is 
  476. deleted from the heap with the "delete" operator.
  477.  
  478. The problem is that the reference class template that I created does not
  479. follow the same conversion rules as standard pointer conversions.
  480. ARM r.4.6 describes that "A pointer to a class may be converted to
  481. a pointer to an accessible base class of that class."  I need that
  482. kind of behavior with my reference class.
  483.  
  484. I have the following example that demonstrates the problem:
  485.  
  486. template <class T>
  487. class JtsRefT
  488. {
  489. private:
  490.         T       *ptr;
  491.  
  492. public:
  493.         JtsRefT (T *t=NULL) : ptr(t) { if (t!=NULL) t->IncRefCount(); }
  494.         ~JtsRefT () { if (ptr!=NULL && ptr->DecRefCount()==0) delete ptr; }
  495.  
  496.         operator T* () const { return ptr; }
  497.  
  498.         const T* operator-> () const { return ptr; }
  499.         T* operator-> () { return ptr; }
  500.  
  501.         const T& operator* () const { return *ptr; }
  502.         T& operator* () { return *ptr; }
  503. };
  504.  
  505. class A
  506. {
  507. private:
  508.         long    refCount;
  509.  
  510. public:
  511.         long IncRefCount () { return ++refCount; }
  512.         long DecRefCount () { return --refCount; }
  513. };
  514.  
  515. typedef JtsRefT<A> AREF;
  516.  
  517. class B : public A
  518. {
  519. };
  520.  
  521. typedef JtsRefT<B> BREF;
  522.  
  523. main ()
  524. {
  525.         BREF bref;
  526.         AREF aref=bref;
  527.  
  528.         return 0;
  529. };
  530.  
  531.  
  532. When compiling on AIX 3.2.5, I correctly get the following error:
  533. "test66.C", line 43.19: 1540-228: (S) No suitable constructor or conversion 
  534. function exists for conversion from "BREF" to "JtsRefT<A>".
  535. make: 1254-004 The error code from the last command is 1.
  536.  
  537. How can I modify my implementation to follow the standard pointer 
  538. conversion ?
  539.  
  540. -thanks
  541. Brian Haskett
  542. haskett@vnet.ibm.com
  543. haskett@applink.net
  544. Newsgroups: comp.lang.c++
  545. Subject: Reference Counting (inheritance)
  546. Summary: 
  547. Expires: 
  548. Sender: 
  549. Followup-To: 
  550. Distribution: 
  551. Organization: AppLink Corp.
  552. Keywords: 
  553.  
  554. Newsgroups: comp.lang.c++
  555. Subject: Reference Counting Pointers to Objects
  556. Summary: 
  557. Expires: 
  558. Sender: haskett@applink.net
  559. Followup-To: 
  560. Distribution: 
  561. Organization: AppLink Corp.
  562. Keywords: 
  563.  
  564. I am attempting to implement reference counting classes that allow me
  565. to have "smart" pointers to database objects.  The reference classes
  566. keep a counter in the db object of how many references are currently 
  567. pointing to that object, and when the count reaches zero, the object is 
  568. deleted from the heap with the "delete" operator.
  569.  
  570. The problem is that the reference class template that I created does not
  571. follow the same conversion rules as standard pointer conversions.
  572. ARM r.4.6 describes that "A pointer to a class may be converted to
  573. a pointer to an accessible base class of that class."  I need that
  574. kind of behavior with my reference class.
  575.  
  576. I have the following example that demonstrates the problem:
  577.  
  578. template <class T>
  579. class JtsRefT
  580. {
  581. private:
  582.         T       *ptr;
  583.  
  584. public:
  585.         JtsRefT (T *t=NULL) : ptr(t) { if (t!=NULL) t->IncRefCount(); }
  586.         ~JtsRefT () { if (ptr!=NULL && ptr->DecRefCount()==0) delete ptr; }
  587.  
  588.         operator T* () const { return ptr; }
  589.  
  590.         const T* operator-> () const { return ptr; }
  591.         T* operator-> () { return ptr; }
  592.  
  593.         const T& operator* () const { return *ptr; }
  594.         T& operator* () { return *ptr; }
  595. };
  596.  
  597. class A
  598. {
  599. private:
  600.         long    refCount;
  601.  
  602. public:
  603.         long IncRefCount () { return ++refCount; }
  604.         long DecRefCount () { return --refCount; }
  605. };
  606.  
  607. typedef JtsRefT<A> AREF;
  608.  
  609. class B : public A
  610. {
  611. };
  612.  
  613. typedef JtsRefT<B> BREF;
  614.  
  615. main ()
  616. {
  617.         BREF bref;
  618.         AREF aref=bref;
  619.  
  620.         return 0;
  621. };
  622.  
  623.  
  624. When compiling on AIX 3.2.5, I correctly get the following error:
  625. "test66.C", line 43.19: 1540-228: (S) No suitable constructor or conversion 
  626. function exists for conversion from "BREF" to "JtsRefT<A>".
  627. make: 1254-004 The error code from the last command is 1.
  628.  
  629. How can I modify my implementation to follow the standard pointer 
  630. conversion ?
  631.  
  632. -thanks
  633. Brian Haskett
  634. haskett@vnet.ibm.com
  635. haskett@applink.net
  636. Newsgroups: comp.lang.c++
  637. Subject: Reference Counting (and Inheritance)
  638. Summary: 
  639. Expires: 
  640. Sender: haskett@applink.net
  641. Followup-To: 
  642. Distribution: 
  643. Organization: AppLink Corp.
  644. Keywords: 
  645.  
  646. Newsgroups: comp.lang.c++
  647. Subject: Reference Counting Pointers to Objects
  648. Summary: 
  649. Expires: 
  650. Sender: haskett@applink.net
  651. Followup-To: 
  652. Distribution: 
  653. Organization: AppLink Corp.
  654. Keywords: 
  655.  
  656. I am attempting to implement reference counting classes that allow me
  657. to have "smart" pointers to database objects.  The reference classes
  658. keep a counter in the db object of how many references are currently 
  659. pointing to that object, and when the count reaches zero, the object is 
  660. deleted from the heap with the "delete" operator.
  661.  
  662. The problem is that the reference class template that I created does not
  663. follow the same conversion rules as standard pointer conversions.
  664. ARM r.4.6 describes that "A pointer to a class may be converted to
  665. a pointer to an accessible base class of that class."  I need that
  666. kind of behavior with my reference class.
  667.  
  668. I have the following example that demonstrates the problem:
  669.  
  670. template <class T>
  671. class JtsRefT
  672. {
  673. private:
  674.         T       *ptr;
  675.  
  676. public:
  677.         JtsRefT (T *t=NULL) : ptr(t) { if (t!=NULL) t->IncRefCount(); }
  678.         ~JtsRefT () { if (ptr!=NULL && ptr->DecRefCount()==0) delete ptr; }
  679.  
  680.         operator T* () const { return ptr; }
  681.  
  682.         const T* operator-> () const { return ptr; }
  683.         T* operator-> () { return ptr; }
  684.  
  685.         const T& operator* () const { return *ptr; }
  686.         T& operator* () { return *ptr; }
  687. };
  688.  
  689. class A
  690. {
  691. private:
  692.         long    refCount;
  693.  
  694. public:
  695.         long IncRefCount () { return ++refCount; }
  696.         long DecRefCount () { return --refCount; }
  697. };
  698.  
  699. typedef JtsRefT<A> AREF;
  700.  
  701. class B : public A
  702. {
  703. };
  704.  
  705. typedef JtsRefT<B> BREF;
  706.  
  707. main ()
  708. {
  709.         BREF bref;
  710.         AREF aref=bref;
  711.  
  712.         return 0;
  713. };
  714.  
  715.  
  716. When compiling on AIX 3.2.5, I correctly get the following error:
  717. "test66.C", line 43.19: 1540-228: (S) No suitable constructor or conversion 
  718. function exists for conversion from "BREF" to "JtsRefT<A>".
  719. make: 1254-004 The error code from the last command is 1.
  720.  
  721. How can I modify my implementation to follow the standard pointer 
  722. conversion ?
  723.  
  724. -thanks
  725. Brian Haskett
  726. haskett@vnet.ibm.com
  727. haskett@applink.net
  728.